﻿using System;
using System.Text;
using SolutionFactory.Exporter;
using SolutionFactory.Services;
using SolutionFactory.UI;

namespace SolutionFactory_console
{
	public class Program
	{
		static void Main(string[] args)
		{
            if(args[0]=="export")
            {
                ExportExistingSolution(args[1], args[2]);
            }
            else
            {
                CreateSolutionFromTemplate(args[1], args[2], args[3]);
            }

			Console.WriteLine("done");
		}

		private static void ExportExistingSolution(string solutionFilename, string outputDirectory)
		{
			TemplateInput input = new TemplateInput();
			input.SolutionFileName = solutionFilename;
			input.IncludeParentDirectory = true;
			input.RunOnCompletion = "click to build.bat";
			input.Category = "CSharp";
			input.SubCategory = "Headspring";
			input.Name = "Headspring Arch Nov 23rd";
			input.Description = "ASP.Net MVC template";
			input.OutputDirectory = outputDirectory;
			CreateExporter()
				.Export(input);
		}

		private static void CreateSolutionFromTemplate(string solutionTemplate, string newSolutionName, string newSolutionDirectory)
		{
			
			CreateExporter().NewProject(solutionTemplate, newSolutionName,newSolutionDirectory);

		}

		private static ExportSolution CreateExporter()
		{
			ILogger logger = new ConsoleLogger();
			var fileSystem = new FileSystem(logger);
			var replacer = new FileTokenReplacer(fileSystem);
			return new ExportSolution(logger, fileSystem,
			                          new FileCopyAndTokenReplacer(fileSystem, logger, replacer), replacer);
		}
	}
}
